﻿using PolePositionMobile.Entities;
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PolePositionMobile
{
    /// <summary>
    /// A form called when a GPS solution is not available
    /// </summary>
    public partial class frmManuallyEnterPosition : frmBase
    {
        //Created by: VMCoder
        //Creation date: -
        //Last updated by: VMCoder
        //Last update: 2008.04.10
        #region Private Members
        private EVisit m_Visit;
        #endregion
        #region Public Properties
        public EVisit Visit
        {
            get { return m_Visit; }
            set { m_Visit = value; }
        }
        #endregion
        public frmManuallyEnterPosition()
        {
            InitializeComponent();
        }

        protected void frmManuallyEnterPosition_Load(object sender, EventArgs e)
        {
            #region Config form
            lblTitle.Text = "PPI | Solution not available";
            lblLButtonText.Text = "Menu";
            lblRButtonText.Text = "Retry";
            lblLButton.ContextMenu = menLButton;
            LButtonMenuXOffset = 1;
            LButtonMenuYOffset = 40;
            #endregion
        }
        protected override void lblRButton_Click(object sender, EventArgs e)
        {
            if (m_GPS.HasSolution)
            {
                ShowLoading();
                Application.DoEvents();
                string stemp = "";
                frmDataCollectionStructure _Form = new frmDataCollectionStructure();
                if (m_Visit == null)
                    m_Visit = new EVisit();
                _Form.Visit = m_Visit;
                _Form.Visit.Longitude = Utils.ConvertLongitudeToDecimal(m_GPS.NmeaGGA.Longitude, m_GPS.NmeaGGA.LongitudeHemisphere, ref stemp);
                _Form.Visit.Latitude = Utils.ConvertLatitudeToDecimal(m_GPS.NmeaGGA.Latitude, m_GPS.NmeaGGA.LatitudeHemisphere, ref stemp);
                _Form.Visit.Altitude = double.Parse(m_GPS.NmeaGGA.Altitude.ToString());
                _Form.Visit.SatelliteCount = m_GPS.NmeaGGA.SateliteCount;
                _Form.Visit.SatelliteTime = m_GPS.NmeaGGA.SateliteTime;
                _Form.Visit.SolutionAvailable = true;
                SetInnerSolutions(_Form.Visit);
                _Form.Settings = this.Settings;
                _Form.Show();
                this.Hide();
            }
        }

        private void mitCancel_Click(object sender, EventArgs e)
        {
            ShowLoading();
            Application.DoEvents();
            frmHomePage _Form = new frmHomePage();
            _Form.Settings = this.Settings;
            _Form.Show();
            this.Hide();
        }

        private void mitSkip_Click(object sender, EventArgs e)
        {
            ShowLoading();
            Application.DoEvents();
            frmDataCollectionStructure _Form = new frmDataCollectionStructure();
            if (m_Visit == null)
                m_Visit = new EVisit();
            _Form.Visit = m_Visit;
            _Form.Visit.Longitude = double.MinValue;
            _Form.Visit.Latitude = double.MinValue;
            _Form.Visit.Altitude = double.MinValue;
            _Form.Visit.SatelliteCount = Int32.MinValue;
            _Form.Visit.SatelliteTime = DateTime.Now.ToUniversalTime();
            _Form.Visit.SolutionAvailable = false;
            SetInnerSolutions(_Form.Visit);
            _Form.Settings = this.Settings;
            _Form.Show();
            this.Hide();
        }
    }
}